/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package repositorio;

import Conexao.Conexao;
import bean.Ramo;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author VENANCIO
 */
public class RamoNegocio implements RamoInt{

    Conexao con;
    Connection c = null;
    
    String sql;
    @Override
    public void Inserir(Ramo ramo) {
        
        
        sql= "INSERT INTO RAMO(RAMO_DESC) VALUE (?)";
        try {
        
            c =  con.getConexao(); 
           
            PreparedStatement st = c.prepareStatement(sql);
            st.setString(1, ramo.getDescricao());
            st.executeUpdate();
            st.close();
       
        } catch (SQLException ex) {
            Logger.getLogger(RamoNegocio.class.getName()).log(Level.SEVERE, null, ex);
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(RamoNegocio.class.getName()).log(Level.SEVERE, null, ex);
        }finally{
            try {
                c.close();
            } catch (SQLException ex) {
                Logger.getLogger(RamoNegocio.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
         
    }

    @Override
    public List<Ramo> listaRamo(Ramo ramo) {
        
        List<Ramo> listRamo = new ArrayList<Ramo>();
        
        
        
        sql = "SELECT * FROM RAMO";
        try {
            c = con.getConexao();
            PreparedStatement st = c.prepareStatement(sql);
            ResultSet rs = st.executeQuery();
            while(rs.next()){
                Ramo r = new Ramo();
                r.setCodRamo(rs.getInt("RAMO_COD"));
                r.setDescricao(rs.getString("RAMO_DESC"));
                listRamo.add(r);
            }
            
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(RamoNegocio.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(RamoNegocio.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        return listRamo;
        
    }

    @Override
    public List<Ramo> listRamo() {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void Alterar() {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void Excluir() {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }
    
}
